﻿@{
    ViewBag.Title = "用户管理——公路工程建设项目造价全过程管理系统";
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">

    var User_jqgrid_lastID = 0; //最后一次选中的行ID
    var User_edit_url = "/Permission/User/UserEditPwd/"; //编辑路径
    var contentHeight_user_index = 0;

    $(document).ready(function () {
        contentHeight_user_index = $("#tabContent").innerHeight() - $(".panelBar", navTab.getCurrentPanel()).outerHeight();
        //        $("#UserTable_user_index").height(contentHeight_user_index);
        //        alert(contentHeight_user_index);
        GridGet();
        initUI();
        $("#Permission_User_AddUser").attr("href", "/Permission/User/AddUser?companyId=" + "@ViewBag.CompanyId" + "&departId=" + "@ViewBag.DepartId" + "&dutyId=" + "@ViewBag.DutyId");
    });

    function GridGet() {
        $("#UserTable_user_index").jqGrid({
            url: "/Permission/User/GetUserByPage",
            datatype: "json",
            mtype: "post",
            colNames: ['ID', '用户名', '姓名', '默认角色', '有效', '操作'],
            colModel: [
                        { name: 'Id', index: 'Id', width: 20, align: "center", sortable: false, hidden: true },
                        { name: 'UserName', index: 'UserName', width: 100, align: "center", sortable: false },
                        { name: 'RealName', index: 'RealName', width: 150, align: "center", sortable: false },
                        { name: 'RoleName', index: 'RoleName', width: 250, align: "center", sortable: false },
                        { name: 'Enabled', index: 'Enabled', width: 350, align: "center", formatter: "checkbox", sortable: false },
                        { name: 'Id', index: 'Id', width: 350, align: "center", sortable: false, formatter: SetUserButtons }
                       ],
            beforeRequest: function (d) {
                $(this).jqGrid('setGridParam', { postData: { 'departId': '@ViewBag.DepartId', 'dutyId': '@ViewBag.DutyId'} });
            },
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_UserTable_user_index");
                ajaxbg.hide();
                $("#UserTable_user_index").initUI();
            },
            onSelectRow: User_GetIDbyEdit,
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            rowNum: 10,
            pager: '#Pager1',
            rowList: [10, 20, 50],
            altRows: true,
            height: contentHeight_user_index - 75
        }).navGrid('#Pager1', { edit: false, add: false, del: false, refresh: false, search: false });
    }

    function SetUserButtons(cellvalue, options, rowData) {
        return "<a style='font-size:12px;color:green;' rel='signedUser' target='dialog' title='电子签名' alt='电子签名' href='/Permission/User/SelectSigned/?userId=" + cellvalue + "'>电子签名</a>";
    }

    //获取所有选中行的ID    1返回行ID   2返回角色ID
    function GetSelectID() {
        var User_Jqgrid = $("#UserTable_user_index");
        var User_Index_Get_ListID = $("#UserTable_user_index").jqGrid("getGridParam", "selrow");
        if (User_Index_Get_ListID == "")
            return "";
        var User_Index_ListID = "";
        var temp = "";
        temp = User_Jqgrid.getCell(User_Index_Get_ListID, "Id").toString();
        if (temp != "" && temp != "false") {
            User_Index_ListID = temp;
        }
        return User_Index_ListID;
    }
    //对用户执行删除操作
    $("#del_permission_user_index").click(function () {
        return User_Delete();
    });

    function User_Delete() {
        var User_Grid_SelectID = GetSelectID();
        if (User_Grid_SelectID == "") {
            alertMsg.error("至少要勾选一条记录！");
            return false;
        }
        else {
            alertMsg.confirm("您确定要删除这些用户吗？", {
                okCall: function () {
                    $.post("/Permission/User/Delete", { "UserArryID": User_Grid_SelectID }, dialogDeleted, "json");
                }
            });
        }
    }

    function dialogDeleted(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            var Jqgrid_ListID = $("#UserTable_user_index").jqGrid("getGridParam", "selrow").toString();
            $("#UserTable_user_index").delRowData(Jqgrid_ListID);
            alertMsg.correct("成功删除1条记录！");
        }
        else {
            alertMsg.error(json.message);
        }
    }

    function dialogCreated(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点       
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            alertMsg.correct(json.message);
            $("#UserTable_user_index").trigger("reloadGrid");
            //            var newRole_row = $("#Role_Create").serialize();
            //            $("#RoleTable").addJSONData(eval(newRole_row));
            $.pdialog.closeCurrent();
            $("#background,#progressBar,#lui_UserTable_user_index").hide();
        }
        else {
            alertMsg.error(json.message);
        }
    }

    function dialogEdited(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点       
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            alertMsg.correct("修改成功！");
            $("#UserTable_user_index").trigger("reloadGrid");
            //            var newRole_row = $("#Role_Create").serialize();
            //            $("#RoleTable").addJSONData(eval(newRole_row));
        }
        else {
            alertMsg.error(json.message);
        }
        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_UserTable_user_index").hide();
    }

    //为修改而获取ID
    function User_GetIDbyEdit(rowid, status) {
        if ($("#UserTable_user_index").jqGrid("getGridParam", "selrow").toString() == "") {
            $("#User_EditPwd").attr("href", "/Permission/User/UserEditPwd/{sid_user}");
            $("#User_Edit").attr("href", "/Permission/User/UserEdit/{sid_user}");
            $("#Permission_User_linkRoles").attr("href", "/Permission/User/linkRoles/{sid_user}");
            $("#Permission_User_selectModule").attr("href", "/Permission/User/selectModule/{sid_user}");
            $("#Permission_User_selectPermission").attr("href", "/Permission/User/selectPermission/{sid_user}");
            return;
        }
        var tempID = 0;
        tempID = $("#UserTable_user_index").getCell(rowid, "Id");
        if (tempID == 0)
            return;
        $("#User_EditPwd").attr("href", User_edit_url + tempID.toString());
        $("#Permission_User_linkRoles").attr("href", "/Permission/User/linkRoles/" + tempID.toString());
        $("#User_Edit").attr("href", "/Permission/User/UserEdit/" + tempID.toString());
        $("#Permission_User_selectModule").attr("href", "/Permission/User/selectModule/" + tempID.toString());
        $("#Permission_User_selectPermission").attr("href", "/Permission/User/selectPermission/" + tempID.toString());
        role_jqgrid_lastID = tempID;
    }
</script>
<div class="page">
    @*顶部按钮*@
    <div class="panelBar" style="border-top:none;">
        <ul class="toolBar">
            <li>@Html.PermissionButton("Permission.User.AddUser", "Permission_User_AddUser", "add", "/Permission/User/AddUser", "User_Add", "dialog", "", "true", "400", "520", "添加")</li>
            <li>@Html.PermissionButton("Permission.User.UserEdit", "User_Edit", "edit", "/Permission/User/UserEdit/{sid_user}", "User_Edit", "dialog", "", "true", "400", "520", "编辑")</li>
            <li>@Html.PermissionButton("Permission.User.Delete", "del_permission_user_index", "delete", "javascript:void(0);", "", "", "", "", "删除")</li>
            <li>@Html.PermissionButton("Permission.User.UserEditPwd", "User_EditPwd", "edit", "/Permission/User/UserEditPwd/{sid_user}", "User_EditPwd", "dialog", "", "true", "340", "240", "修改密码")</li>
            <li>@Html.PermissionButton("Permission.User.linkRoles", "Permission_User_linkRoles", "linkuser", "/Permission/User/linkRoles/{sid_user}", "User_linkRoles", "dialog", "", "true", "360", "480", "关联角色")</li>
            <li>@Html.PermissionButton("Permission.User.selectModule", "Permission_User_selectModule", "menuright", "/Permission/User/selectModule/{sid_user}", "User_selectModule", "dialog", "", "true", "360", "480", "关联模块")</li>
            <li>@Html.PermissionButton("Permission.User.selectPermission", "Permission_User_selectPermission", "conrtolright", "/Permission/User/selectPermission/{sid_user}", "User_selectPermission", "dialog", "", "true", "360", "480", "分配操作权限")</li>
        </ul>
    </div>
    <div id="mainContent_user_index">
            <table id="UserTable_user_index">
            </table>
            <div id="Pager1">
            </div>
    </div>
</div>
